package com.authManager.server.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;

import com.authManager.server.service.ISysUserService;
import com.authManager.server.dao.SysUserMapper;
import com.authManager.entity.SysUser;

import com.commons.base.model.AdminPage;
import com.commons.base.model.ResultCode;
import com.commons.base.model.ResultData;

/**
 * <p>
 * 【用户信息】 服务实现类
 * </p>
 *
 * @author 小旋风
 * @since 2018-8-10
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);

	@Override
	public ResultData<AdminPage<SysUser>> listSysUser(Map<String, Object> paramMap) {
		Page<SysUser> page = new Page<>(Integer.valueOf(String.valueOf(paramMap.get("pageNum"))),
				Integer.valueOf(String.valueOf(paramMap.get("pageSize"))));
		Wrapper<SysUser> entityWrapper = new EntityWrapper<>();

		// 主键id 改成字符串类型
		if (paramMap.get("sysUserId") != null) {
			entityWrapper.like("sys_user.sys_user_id", String.valueOf(paramMap.get("sysUserId")));
		}
		// 用户名
		if (paramMap.get("name") != null) {
			entityWrapper.like("sys_user.name", String.valueOf(paramMap.get("name")));
		}
		// 手机号
		if (paramMap.get("phone") != null) {
			entityWrapper.like("sys_user.phone", String.valueOf(paramMap.get("phone")));
		}
		// 开始-创建日期
		if (paramMap.get("start_createTime") != null) {
			entityWrapper.le("sys_user.create_time", paramMap.get("start_createTime"));
		}
		// 结束-创建日期
		if (paramMap.get("end_createTime") != null) {
			entityWrapper.le("sys_user.create_time", paramMap.get("end_createTime"));
		}
		this.selectPage(page, entityWrapper);
		return new ResultData.Builder<AdminPage<SysUser>>(ResultCode.success).setData(new AdminPage<SysUser>(page))
				.build();
	}
}
